<?php
require_once 'Includes/viewer_functions.php';

if (isset ( $_GET ['model'] )) {
	require_once "../Model/" . $_GET ['model'] . ".php";
	$model = $_GET ['model'];
} else {
	die ( "model must be provided" );
}

if (isset ( $_GET ['primary_key_value'] )) {
	$primary_key_value = $_GET ['primary_key_value'];
	//get Model
	$class_vars = get_class_vars ( $model );
	$primary_key_field = $class_vars ['primary_key_field'];
	$constructor = "constructFrom_$primary_key_field";
	$class_instance = new $model ( );
	
	//construct the class
	$parent = $class_instance->$constructor ( $primary_key_value );
} else {
	die ( "must provide primary_key_value" );
}

if (isset ( $_GET ['foreign_key_field'] )) {
	$foreign_key_field = $_GET ['foreign_key_field'];
} else {
	die ( "must provide foreign_key_field" );
} 

$foreign_key_getter = "get" . $foreign_key_field;
$foreign_key_objects = $parent->$foreign_key_getter ();
?><table><?php
	$titlesRendered = false;
	foreach ( $foreign_key_objects as $foreign_class_instance ) {
		$model_properties = get_object_vars ( $foreign_class_instance );
		//only render titles once
		if (! $titlesRendered) {
			renderPropertiesInputsTitles ( $foreign_class_instance, $model_properties, $ignore_properties );
			$titlesRendered = true;
		}
		//TODO: add custom tags for ignoring properties for individual items
		renderPropertiesInputsRows( $foreign_class_instance, $model_properties, $ignore_properties );
	
	}
	?></table><?php
	?>